<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/3/28
 * Time: 14:21
 */

namespace app\admin\controller;


use app\admin\model\IndexModel;
use app\admin\model\UpdateLogsModel;
use think\Request;

class Index extends Base
{
    protected $indexModel;

    /*
     * 依赖注入Model
     * */
    public function __construct(IndexModel $indexModel){
        parent::__construct();
        $this->indexModel = $indexModel;
    }

    /*
     * 列表
     * */
    public function index_index(){
        $this->assign("data",$this->indexModel->listAll());
        return $this->fetch('index/index');
    }

    /*
    * 新增
    * */
    public function index_add(){
        if(Request::instance()->isPost()){
            $validate=$this->indexModel->validate_model('add');
            if ($validate['code']){
                return $this->indexModel->add();
            }else{
                return $validate;
            }
        }
        return $this->fetch('index/add');
    }

    /*
    * 修改
    * */
    public function index_edit(){
        if(Request::instance()->isPost()){
            $validate=$this->indexModel->validate_model('edit');
            if ($validate['code']){
                return $this->indexModel->edit();
            }else{
                return $validate;
            }
        }
        $id=input('get.id/d');
        $this->assign("data",$this->indexModel->getById($id));
        return $this->fetch('index/edit');
    }

    /*
    * 删除
    * */
    public function index_del(){
        return $this->indexModel->del();
    }


}